package cn.cy.behavior.observer.event.normal;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yangxq
 * @desc 事件源
 * @date 2025-05-07
 */
public class EventSource {

    private List<EventListener> listeners = new ArrayList<>();

    public void addListener(EventListener listener) {
        listeners.add(listener);
    }

    public void removeListener(EventListener listener) {
        listeners.remove(listener);
    }

    public void triggerEvent(String message) {
        Event event = new Event(message);
        for (EventListener listener : listeners) {
            listener.onEvent(event); // 通知所有监听器
        }
    }

}
